<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Member extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->library('Huashang/user');
		$this->user->checkLogin();
	}
	//载入会员列表
	public function index(){
		$data['type']=$this->uri->segment(3);
	    $data['auth']=explode(',', $this->input->get('auth'));
		$this->load->view('member/index',$data);
	}
	//获取会员列表
	public function getlist(){
		$arr=array('total'=>10000,'rows'=>array(
			array('id'=>1,'t1'=>'在线', 't2'=>'张三',
			't3'=>'eprgdip','t4'=>'未分层','t5'=>'555555.34','t6'=>'mrdailishang(默认代理商)',
			't7'=>'2017-02-09 09:23:25','t8'=>'停用')
			
		));
	    echo json_encode($arr);
	}
	//保存会员列表
	public function save(){
		$id = $this -> input -> post('id');
		if($this -> user -> save($id,$row) && $this -> admin_sh -> add($sh)){
			echo '{"status":"OK","msg":"执行成功"}';
		}else{
			echo '{"status":"ERROR","msg":"执行失败"}';
		}
	}
	//修改会员
	public function edituser(){
		$data['rs']=array_pop($this->user->update());
		$this->load->view('member/edituser',$data);
	}
	//获取分层信息
	public function getfc(){
		$this->load->view('member/fcinfo');
	}

	//基本资料设定
	public function basic_info(){
		$this->load->view('member/basic_info');
	}

	//删除会员
	public function deluser(){
		$this->user->remove();
	}

	//详细资料设定
    public function detail_info(){
	    $data = array(
	        'account' => 'MRl',
            'real_name' => '骆sir',
            'birthday' => '1997-7-8',
            'region' => '广东省广州赛大富翁街道234号',
            'id_card' => '429345198411123234',
            'phone' => '155344433334',
            'qq' => '1553444333',
            'email' => '1553444333@qq.com',
            'bank_name' => array('中国建设银行','中国人民银行','中国工商银行'),
            'bank_account' => '6554 8897 8784 344',
            'bank_password' => '1234',
            'remark' => '',
            'register_ip' => '192.168.0.1',
            'register_time' => '2017-02-09 12:11:34',
            'last_login_time' => '2017-02-09 12:11:34',
            'last_login_ip' => '23.233.43.1'
        );
	    $this->load->view('member/detail_info', $data);
    }
	/*********************************代理************************************/
	//载入列表
	public function agent(){
		$data['type']=$this->uri->segment(3);
	    $data['auth']=explode(',', $this->input->get('auth'));
		$this->load->view('member/agent',$data);
	}
	//获取会员列表
	public function getagent(){
		$arr=array('total'=>0,'rows'=>array(
			array('id'=>1,'t1'=>'在线', 't2'=>'张三',
			't3'=>'eprgdip','t4'=>'未分层','t5'=>'555555.34','t6'=>'mrdailishang(默认代理商)',
			't7'=>'2017-02-09 09:23:25','t8'=>'停用')
			
		));
	    echo json_encode($arr);
	}
	
	//修改
	public function editagent(){
		$data['rs']=array_pop($this->user->update());
		$this->load->view('member/editagent',$data);
	}

	//代理资料设定
	public function agent_info(){
		$this->load->view('member/agent_info');
	}

	//注册会员优惠设定
	public function member_discount(){
		$this->load->view('member/member_discount');
	}

	// 获取代理占成列表
    public function get_discount_list(){
        $data = array(
            'total' => '10',
            'list' => array(
                array('id' => 1, 'name' => '全成'),
                array('id' => 2, 'name' => '9.5成'),
                array('id' => 3, 'name' => '9.0成'),
                array('id' => 4, 'name' => '8.5成'),
                array('id' => 5, 'name' => '8.0成'),
                array('id' => 6, 'name' => '7.5成'),
                array('id' => 7, 'name' => '7.0成'),
                array('id' => 8, 'name' => '6.5成'),
            )
        );
        echo json_encode($data, JSON_UNESCAPED_UNICODE);
    }

	/*********************************子帐号************************************/
	//载入列表
	public function child(){
		$data['type']=$this->uri->segment(3);
	    $data['auth']=explode(',', $this->input->get('auth'));
		$this->load->view('member/child',$data);
	}
	//获取列表
	public function getchild(){
		$arr = json_decode($this->curl_post(ADMINAPI.'manager/get_child_list',$_POST),true);
	    echo json_encode($arr['data']);
	}
	
	//修改
	public function editchild(){
		$data['rs'] = array();
		if(!empty($_GET['id'])){
			$data['rs'] = array_pop(json_decode($this->curl_get(ADMINAPI.'manager/get_info?admin_id='.$_GET['id']),true));
		}
		$this->load->view('member/editchild',$data);
	}
	//保存修改
	public function save_child(){
		$id =$this->input->post('admin_id');
		$pwd = $this->input->post('pwd');
		$two_pwd =$this->input->post('two_pwd');
		if($pwd!==$two_pwd){
			exit($this->status('ERROR','两次密码不一致'));
		}
		$rs = json_decode($this->curl_post(ADMINAPI.'manager/update_user',$_POST),true);
		if($rs['code']==200){
			exit($this->status('OK','执行成功'));
		}else{
			exit($this->status('ERROR',$rs['msg']));
		}
		

	}
	//获取权限
	public function get_power(){
		$data['public'] = file_get_contents('static/data/public_menu.json');
		if(!empty($_GET['id'])){
			$data['rs'] = array_pop(json_decode($this->curl_get(ADMINAPI.'manager/get_info?admin_id='.$_GET['id']),true));
			$auth=$data['rs']['privileges'];
			if($auth=='*'){
				$data['rs']['privileges']=[];
			}else if(empty($data['rs']['privileges'])){
				$data['rs']['privileges']=[];
			}
		}
		$this->load->view('member/get_power',$data);
	}
	//保存权限
	public function save_power(){
		$top_menu    = $this->input->post('top_menu');
		$sub_menu    = $this->input->post('sub_menu');
		$act=array();
		foreach($top_menu as $k=>$v){
			foreach($v as $i=>$s){
				foreach($sub_menu[$k][$s] as $e=>$o){
					$act[$k][$s][$e]=$o;
				}
			}
		}
		$row['privileges']=json_encode($act);
		$row['admin_id']=$this->input->post('admin_id');
		$row['max_credit_out_in']    = $this->input->post('max_credit_out_in');
		$row['max_credit_in_people'] = $this->input->post('max_credit_in_people');
		$this->curl_post(ADMINAPI.'manager/save_privilege',$row);
		echo '{"status":"OK","msg":"执行成功","id":"1"}';
	}
	//删除管理员
	public function delete_user(){
		$rs=json_decode($this->curl_post(ADMINAPI.'manager/delete_user',array('admin_id'=>$_POST['id'])),true);
		if($rs['code']==200){
			exit($this->status('OK','执行成功'));
		}else{
			exit($this->status('ERROR',$rs['msg']));
		}
	}


	//修改管理员状态
	public function update_status(){
		$rs=json_decode($this->curl_post(ADMINAPI.'manager/update_status',array('admin_id'=>$_POST['id'],'status'=>$_POST['status'])),true);
		if($rs['code']==200){
			exit($this->status('OK','执行成功'));
		}else{
			exit($this->status('ERROR',$rs['msg']));
		}
	}

}